﻿#ifndef __HERO_H_
#define __HERO_H_
#include "ui/CocosGUI.h"
#include "cocos2d.h"
class Hero : public cocos2d::ui::Widget {
public:
	static Hero* create();
	bool init();
	void initBulletCountArr();
	void loadUserInfo();
	void initCSBFile();//加载CSB文件
	void initHero();//初始化主机
	void initWeapon();//初始化僚机
	void collectionHero();//回收自己
	static Hero* getInstance() {
		if (nullptr == pInstance) {
			pInstance = create();
		}
		return pInstance;
	}
	//开启触摸监听
	void openTouchListener();

	//当触摸开始时，要执行的函数
	bool onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event);

	//当触摸移动时，要执行的函数
	void onTouchMoved(cocos2d::Touch* touch, cocos2d::Event* event);

	//当触摸取消时，要执行的函数
	void onTouchEnded(cocos2d::Touch* touch, cocos2d::Event* event);

	void shootUpdate(float dt);
	void weaponShootUpdate(float dt);
	void createBullet(int posX);
	void createWeaponBullet();
	void isOpenShoot(bool result, float delay = 0);//是否开启射击调度器
	cocos2d::Vec2 getHeroPos()const {
		return heroPos;
	}
	int getAtk() const {
		return atk;
	}
	int getWeaponAtk() const {
		return weaponAtk;
	}
	void setInvincibleState(bool state) {
		invincibleState = state;
	}
	bool getInvincibleState()const {
		return invincibleState;
	}
	bool getHeroState()const {
		return live;
	}
	void setMove(int move) {
		isMove = move;
	}
	bool getMoveState() const{
		return isMoveing;
	}
	void die();//主机死亡
	void isEnhancedRateOfFire(bool flag);
	void isEnhancedFirepower(bool flag);
	bool getPerformWondersState()const {
		return isPerformWonders;
	}
	void setPerformWonders(bool flag) {
		isPerformWonders = flag;
	}
	cocos2d::Rect getHeroRect();
public:
	typedef std::function<void()> onTouchBeganCallback;
	typedef std::function<void()> onTouchEndedCallback;

	onTouchBeganCallback onTouchBeganCall;//指向当冷却开始时要调用的函数
	onTouchEndedCallback onTouchEndedCall;//指向当冷却结束时要调用的函数
private:
	static Hero* pInstance;
	Hero();
private:
	cocos2d::Sprite* hero;
	cocos2d::Sprite* weapon_left;
	cocos2d::Sprite* weapon_right;
	cocos2d::Sprite* weapon_bullet_boom;
	cocos2d::Sprite* dieSp;
	cocos2d::Sprite* gameBg;
	cocos2d::Node* root;
	int bulletCount;
	int atk;
	int strengthenATK;
	int weaponAtk;
	float weaponShesu;
	int bulletCountArr[11];
	bool isMove;
	bool isMoveing;//是否正在移动
	bool live;
	bool invincibleState;//英雄无敌状态
	bool isPerformWonders;//是否点石成金
	cocos2d::Vec2 heroPos;
	cocos2d::Size heroSize;
	cocos2d::Size weaponSize;
	cocos2d::Size size;
	char filename[40];
};
#endif // !__HERO_H_

